//
// Created by Administrator on 2021/10/20.
//
#include "function1.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

void displayScore(vector<int>& scores)
{
    // use sort scores in ascending order
    sort(scores.begin(), scores.end(), [](int a, int b){return a < b;});

    // use for_each to display all scores.
    for_each(scores.rbegin(), scores.rend(), [](int& x){cout << x << " ";});

    cout << "\nHighest score: ";
    // use max_element to find the highest score.
    cout << *(max_element(scores.begin(), scores.end()));

    cout << "\nLowest score: ";
    // use min_element to find the lowest score.
    cout << *(min_element(scores.begin(), scores.end()));

    cout << "\nPerfect scores: ";
    // use count to display number of scores equal to 100.
    cout << count(scores.begin(), scores.end(), 100);

    cout << "\nScore count: ";
    // use vector::size to display the total number of scores.
    cout << scores.size();

    cout << "\nScore total: ";
    // use accumulate to calculate total of all scores.
    int totalScore = accumulate(scores.begin(), scores.end(), 0);
    cout << totalScore;

    cout << "\nAverage score: ";
    // use round to round the decimal part.
    cout << round((float)totalScore / (float)scores.size() * 10) / 10;
}
